package com.orilife.trade;

import java.util.ArrayList;
import java.util.List;

import com.example.orllife.R;
import com.orilife.adapter.FinalOrderAdapter;
import com.orilife.bean.ConfirmOrder;
import com.orilife.bean.Order;
import com.orilife.connectdata.GetTradeInfo;


import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class MyAlreadyFinishedFragment extends Fragment {
	 ListView orderListView;
	    List<ConfirmOrder> confirmOrderList;
		FinalOrderAdapter adapter;
		int pageSize=10,refresh=0,next=0;
		String userToken;
		
	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.myalreadyfinishedfragmentlayout, container,
				false);
		orderListView = (ListView)view.findViewById(R.id.myfinishedlistview);
		orderListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getActivity(),OrderDetailsActivity.class);
				intent.putParcelableArrayListExtra("orderlist", (ArrayList<? extends Parcelable>) confirmOrderList.get(position).getOrderList());
				startActivity(intent);
			}
		});
		return view;
	}
	
	
	
	@Override
	public void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		SharedPreferences sp = getActivity().getSharedPreferences("orilife",Activity.MODE_PRIVATE);
		userToken = sp.getString("userid", null);
		Thread thread = new Thread(new getTotalRefreshOrder());
		thread.start();
//		adapter = new FinalOrderAdapter(getActivity());
//		adapter.setData(confirmOrderList);
//		orderListView.setAdapter(adapter);
	}
	
	
	

	 class getTotalRefreshOrder implements Runnable{

		@Override
		public void run() {
			// TODO Auto-generated method stub
			GetTradeInfo.getTotalRefreshConfirmOrder(userToken, pageSize, refresh);
		}
		 
	 }


}
